/**
 *Project: jh-frameworks
 *File: cn.xkshow.framework.web.action.UniversalAction.java 
 *Author: hardy(admin@xkshow.cn) Copyright
 ****************************************************************
 *   VERSION       DATE            BY       CHANGE/COMMENT
 * --------------------------------------------------------------
 *    1.0        2013-9-27         hardy         create
 ****************************************************************
 *note:
 ***************************************************************/ 
package cn.xkshow.framework.web.action;

import java.io.Serializable;
import java.util.Map;

import cn.xkshow.framework.service.UniversalService;
import cn.xkshow.util.ConvertHelper;

public abstract class UniversalAction<T> extends BaseMainAction {
	protected UniversalService<T> universalService;

	/*
	 * (non-Javadoc)
	 * Abstract.method
	 */		
	public abstract String search();	
	
	public abstract String view();
	
	public abstract String save();
	
	/*
	 * (non-Javadoc)
	 * Method.Implemented: Internal
	 */
	protected void findPageList(boolean isHQL, String querystring, Map<String, Object> paramMap, Integer viewLine, String pgurl){
		if(isHQL){
			super.setPageList(this.universalService.findPageListByHql(querystring, paramMap, super.getPage(viewLine, pgurl)));
		}else{
			super.setPageList(this.universalService.findPageListBySql(querystring, paramMap, super.getPage(viewLine, pgurl)));
		}
	}
	
	protected T viewByKey(Object cla, String key, Object value){
		if(cla!=null && null!=value){
			if(null == key){
				return this.universalService.getEntity((Class<T>)cla.getClass(), (Serializable)value);				
			}
			return this.universalService.getEntity((Class<T>)cla.getClass(), key, value);
		}
		return null;
	}
	
	public void setUniversalService(UniversalService<T> universalService) {
		this.universalService = universalService;
	}

}
